using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Cartoon
{
    public partial class ComicForm : Form
    {
        LinkLabel StandardControl = new LinkLabel();    

        public ComicForm()
        {
            InitializeComponent();
        }

        private void ComicForm_Load(object sender, EventArgs e)
        {
        }

        public void DownActivate()
        {
            try
            { 
                ICollection<Episode> episodes = HtmlAnalyze.GetComic(Global.NewComicUrl);          

                List<Control> controls = new List<Control>();
                foreach (Control control in m_ControlContainer.Controls)
                {
                    control.Size = StandardControl.Size;
                    controls.Add(control);
                }

                for (int i = controls.Count; i < episodes.Count; ++i)
                {
                    LinkLabel control = new LinkLabel();
                    controls.Add(control);
                    control.Click += new EventHandler(control_Click);
                }

                m_ControlContainer.Clear();

                int index = 0;                
                foreach (Episode episode in episodes)
                {
                    LinkLabel control = controls[index] as LinkLabel;
                    
                    control.Text = episode.Name;
                    control.Tag = episode.Url;
                    index++;
                }

                m_ControlContainer.AddRange(controls.ToArray());
            }
            catch
            {

            }            
        }

        void control_Click(object sender, EventArgs e)
        {
            Process.Start(((LinkLabel)sender).Tag.ToString());
        } 
    }
}